﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Management/Manage.Master" %>

<%@ Import Namespace="CSI.Directory.Core.Model" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Show Articles
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function(){
    
        $("a").removeClass("current");
        $("#users").addClass("current");
        var e = jQuery.Event("click"); 
        $("#users").trigger(e);
        $("#list-users").addClass("current");

    });

    function Delete(id) {
        var answer = confirm("Delete this user?")
        if (answer) {
            DeleteArticle(id);
        }

        return false;
    }

    function DeleteUser(id) {
       
       
        $("#results").html("");
        $.ajax({
            type: "POST",
            url: "/Management/DeleteUser/" + id,
            error: function(xhr, status, error) {
            },
            success: function(response) {
                if (response != null) {
                    if (!response.Successful) {
                        $("#results").html("An error occurred: " + response.Exception).addClass("red");
                        return false;
                    }
                    else {
                        window.location.reload();
                    }
                }
            }
        });
       
    }
</script>
    <div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header">
            <h3>
                Manage Users</h3>
            
            <div class="clear">
            </div>
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
        <div id="results"></div>
            <div class="tab-content default-tab" id="tab1">
                
                <table>
                    <thead>
                        <tr>
                            <th>
                                Name
                            </th>
                            <th>
                                Email
                            </th>
                            <th>
                                Role
                            </th>
                            
                            <th colspan="2">
                                Actions
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <%  foreach (var u in (IList<User>)ViewData["Users"])
                            { %>
                        <tr>
                            <td>
                                <a href="/Management/EditUSer/<%= u.Id%>" ><%=u.Name %></a>
                            </td>
                            <td>
                                <%=u.Email %>
                            </td>
                            <td>
                                <%=u.Roles %>
                            </td>
                            <td>
                                <a href="/Management/EditUSer/<%= u.Id%>" >Edit</a>
                            </td>
                            <%--<td>
                                <a href="" onclick="Delete(<%= u.Id%>);">Delete</a>
                            </td>--%>
                        </tr>
                        <%} %>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</asp:Content>
